package it.low.game.core.action;

import it.low.game.core.element.ActiveElement;
import it.low.game.core.element.activity.Targetable;
import it.low.game.core.location.MapPoint;

public class Follow extends Move {
				
	public Follow(Targetable target) {
		super(target);		
	}

	public boolean run(ActiveElement executor, long elapsedTime){
		boolean isFinish = false;
		double delta = executor.getProperty(ActiveElement.RUN_SPEED)*elapsedTime;
		endMapPosition = targets[0].getMapPosition();
		if(endMapPosition!=null){
			if(executor.getMapPosition().isNear(endMapPosition,executor.getProperty(ActiveElement.SIG_RANGE))){
				if(executor.getMapPosition().isNear(endMapPosition,executor.getProperty(ActiveElement.ATT_RANGE))){
					isFinish = false;
				}else{
					this.setPath(executor.getMapPosition(), targets[0].getMapPosition());
					double deltaX = delta*sinAlpha;
					double deltaY = delta*cosAlpha;							
					double newLocationX = executor.getMapPosition().getX() + deltaX;
					double newLocationY = executor.getMapPosition().getY() + deltaY;
					executor.setMapPosition(new MapPoint(newLocationX,newLocationY));
				}	
			}else{				
				isFinish = stop();
			}
		}
		return isFinish;
	}
	
}
